﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Ionic.Zip;


namespace ShadowEraDeckEditor
{
    class Deckdb
    {
        private int ID;
        private string name;
        private string race;
        private string type;
        private string cClass;
        private string wepSecondClass;
        private MemoryStream picURL = new MemoryStream();
        


        /*public Deckdb(int i, string n, string r, string t, string c, string wc)
        {

            ID = i;
            name = n;
            type = t;
            race = r;
            cClass = c;
            wepSecondClass = wc;
            picURL = null;
        }*/
        //revised constructor that accepts strings from DB
        public Deckdb(string s)
        {
            //split input in to 6 parts
            string[] splitS = s.Split(',');
            int i;
            //convert first part to int and output as ID
            int.TryParse(splitS[0], out i);
            ID = i;
            //write remaining strings to respective areas
            name = splitS[1];
            race = splitS[2];
            type = splitS[3];
            cClass = splitS[4];
            wepSecondClass = splitS[5];

            //Create a new subfolder under the current active folder
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            //this combine function can be used with second argument as filename, too
 //           appPath = System.IO.Path.Combine(appPath, "images");
            
            //MemoryStream thepicture = new MemoryStream();

            string picURLtemp = null;
            if (i < 100)
                picURLtemp = "0";
            if (i < 10)
                picURLtemp = "00";
            string picEntry = "images\\se" + picURLtemp + i +".jpg";
            try
            {
                using (ZipFile zip = ZipFile.Read("carddb.dat"))
                {
                    zip.Password = "c@n7cr4kD1zSh!t";
                    ZipEntry z = zip[picEntry];
                    z.Extract(picURL);

                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            //pictureBox1.Image = Image.FromStream(thepicture);
            //append 0s where needed for card URL

            //write the card picURL in complete format
            //picURL = "http://www.shadowera.com/cards/se";
  /*          picURL = appPath + "\\se";
            if (picURLtemp != null)
            {
                picURL += picURLtemp;
            }
            picURL += ID.ToString() + ".jpg"; */
        }

        public string cardName
        {
            get { return name; }
        }
        public int cardID
        {
            get { return ID; }
        }
        public string cardRace
        {
            get { return race; }
        }
        public string cardType
        {
            get { return type; }
        }
        public string cardClass
        {
            get { return cClass; }
        }
        public string cardWepClass
        {
            get { return wepSecondClass; }
        }
        public MemoryStream cardURL
        {
            get { return picURL; }
        }
    }
}
